#!/usr/bin/env bash
# Check that all files embedded with file-embed are declared in extra-source-files

set -e

echo "Checking embedded file declarations:"
status=0
for f in $(find . -name '*.hs' | xargs grep -E '\$\(embedFile' | sed -E 's/.*\$\(embedFile[^ ]* "([^"]+)".*/\1/'); do
    if output=$(grep -l "$f" -- */package.yaml); then
        printf '%-40s\tdeclared in %s\n' "$f" "$output"
    else
        printf '%-40s\tUNDECLARED\n' "$f"
        status=1
    fi;
done

if [[ $status != 0 ]]; then echo FAIL; else echo ok; fi
exit $status
